package SocialMediaSentiment;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class testValidationPerceptron{
	public static void main(String args[]){
		test();
	}
	
	public static void test(){
		int  sentiment,fouten=0,counter=0, classified,sentot=0,neuttot=0,senclasstot=0,senfout=0,neutfout=0,senclassfout=0;
		//HashMap <String, Integer> tweets = new HashMap<String, Integer>();
		String tweet;
		String file = "testset.xls";
		File input = new File("boundery.txt");
		float boundery = new Float(StandardFunctions.deserializeString(input));
		System.out.println(boundery);
		Map<String, Double> woordenweightslijst = StandardFunctions.getWeightsList("CompareZeroNonZero.xls");
		
		try {
			String[] data;

			HashMap<Integer, String[]> temp = ReadExcel.read(file, 9, 4);
			Iterator<Integer> k = temp.keySet().iterator();
			while(k.hasNext()){
				data = temp.get(k.next());
				tweet = data[0];
				Map<Integer, HashMap<String, Double>> tweetData = StandardFunctions.TweetClassifyData(tweet, boundery, woordenweightslijst);
				Iterator<Integer> k1 = tweetData.keySet().iterator();
				classified = (int) k1.next();
				HashMap<String, Double> tweetWeights = tweetData.get(classified);
				Iterator<String> k2 = tweetWeights.keySet().iterator();
				int words = tweetWeights.size();
				double[] weights = new double[words];
				int i=0;
				while (k2.hasNext()){
					weights[i]=tweetWeights.get(k2.next());
					
					i++;
				}
				Arrays.sort(weights);
				//System.out.printf("0: %f end: %f\n",weights[0],weights[weights.length-1]);
				sentiment = (Integer.parseInt(data[1])!=0)?1:0;
				sentot+=sentiment;
				neuttot+=(sentiment==0)?1:0;
				senclasstot+=classified;
				if(classified!=sentiment){
					senfout+=sentiment;
					neutfout+=(sentiment==0)?1:0;
					senclassfout+=classified;
					fouten++;
					
				}
				counter++;
				
				
				//tweets.put( tweet, sentiment );
				
			}
			System.out.printf("totaal: %d fouten: %d\t percentage: %f\tsentiment: %d fout: %d\tneutraal: %d fout %d\n", counter, fouten, ((double)fouten/counter)*100,sentot,senfout,neuttot,neutfout);
			System.out.printf("classified:\n\t%d sentiment\t%d no senitment\t %d sentiment fout",senclasstot,counter-senclasstot,senclassfout);
		} catch (IOException e) {
			e.printStackTrace();
			System.err.println("Unable to read "+file);
		}
		
	
	}
}
